Skip to content

WIP/REF/FIX: Don't throw away exception stack traces #1490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jun 8, 2016

Conversation

berleant
Copy link
Contributor

@berleant berleant commented Jun 1, 2016

I found some places in the code where exceptions were being caught and a new exception being thrown without the stack trace or any other relevant info. This makes it hard to debug and figure out what errors mean. Python 3 introduced a raise ... from language construct that makes it easier to chain exceptions and keep the stack trace/other relevant info. The future module allows similar behavior in Python 2 with the raise_from function, which I've used here.

I would also like to propose adding a guideline for contributing to nipype with wording like (first draft, suggestions welcome): "In general, do not catch exceptions without good reason. Good reasons include catching non-fatal exceptions and adding more information about what may have caused the error. A caught exception must be either 1) rethrown inside a new exception using future's raise_from, or 2) logged. Do not do both (creates confusing output)."

Another note (for a future PR?): We probably should not be using/catching the Exception class without subclassing it (per python documentation: https://docs.python.org/3/library/exceptions.html).

@@ -459,9 +460,9 @@ def create_average_networks_by_group_workflow(group_list, data_dir, subjects_dir
try:
l4infosource.inputs.group_id1 = list(group_list.keys())[0]
l4infosource.inputs.group_id2 = list(group_list.keys())[1]
except IndexError:
except IndexError as e:
print('The create_average_networks_by_group_workflow requires 2 groups')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we include this in the Exception message rather than print it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thanks for catching that.

@berleant
Copy link
Contributor Author

berleant commented Jun 1, 2016

This change unfortunately decreased test coverage significantly. To test my changes, I would like to use the auto-test-maker to define inputs that should induce exceptions and write tests, but I am not sure how or if that's possible. Thoughts?

except KeyError:
raise ImportError("This loader does not know module " + fullname)
except KeyError as e:
raise_from(ImportError("This loader does not know module " + fullname), e)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this is an external package, we shouldn't make this change. it may also be time to update the six.py included in nipype.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Are all the files in external this way? If possible, we should avoid this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should update external files before a release, but any changes should really be upstream. six and future are competing packages and at present we are using both. it will require a focused sprint to use one or the other.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, that makes sense

@satra
Copy link
Member

satra commented Jun 5, 2016

@shoshber - can you merge with upstream master?

regarding the auto-test-makter, this wouldn't generally be covered under that. how, about testing a few basic test cases that would show error propagation?

Conflicts:
	nipype/pipeline/plugins/ipython.py
@berleant
Copy link
Contributor Author

berleant commented Jun 7, 2016

how, about testing a few basic test cases that would show error propagation?

Will definitely do that--doctest appears to have a pretty good builtin way to do it, I might try that

@berleant berleant changed the title REF/FIX: Don't throw away exception stack traces WIP/REF/FIX: Don't throw away exception stack traces Jun 7, 2016
@coveralls
Copy link

coveralls commented Jun 8, 2016

Coverage Status

Coverage increased (+0.02%) to 72.091% when pulling 49e3272 on shoshber:raise_from into 124a850 on nipy:master.

@coveralls
Copy link

coveralls commented Jun 8, 2016

Coverage Status

Coverage increased (+0.02%) to 72.09% when pulling 620910c on shoshber:raise_from into 124a850 on nipy:master.

@satra
Copy link
Member

satra commented Jun 8, 2016

@shoshber - this is looking good. should we merge this or are you planning to add more tests?

If you think I've added enough tests, then let's merge!

@berleant berleant merged commit abe7920 into nipy:master Jun 8, 2016
@@ -45,6 +45,7 @@ install:
- if [ ${TRAVIS_PYTHON_VERSION:0:1} == "2" ]; then conda install --yes vtk; fi
- pip install python-coveralls
- pip install nose-cov
- pip install mock
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be removed from here and added to https://github.com/nipy/nipype/blob/master/nipype/info.py? Same thing goes for circle.yml. (this way users will be able to run tests)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants